package algorithm_optimal_solution.StackAndQueue;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;

public class GetMinOfStack {

    public static Stack<Integer> stackData = new Stack<>();
    public static Stack<Integer> stackMin = new Stack<>();

    public void push(Integer xNumber){
        stackData.push(xNumber);
        if(stackMin.isEmpty() || xNumber <= stackMin.peek()){
            stackMin.push(xNumber);
        }
    }

    public void pop(){
        if(stackData.isEmpty()){
            throw new RuntimeException("stack is empty");
        }
        Integer value = stackData.pop();
        if(stackMin.peek() == value){
            stackMin.pop();
        }
    }

    public Integer getMin(){
        if(stackMin.isEmpty()){
            throw new RuntimeException("stack is empty");
        }
        return stackMin.peek();
    }

    public static void main(String[] args)throws IOException{
        GetMinOfStack main = new GetMinOfStack();
        BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
        int len= Integer.parseInt(scanner.readLine());
        for(int i=0;i<len;i++){
            String value = scanner.readLine();
            if(value.equals("pop")){
                main.pop();
            }else if(value.equals("getMin")){
                System.out.println(main.getMin());
            }else{
                String[] result= value.split(" ");
                main.push(Integer.valueOf(result[1]));
            }
        }
        scanner.close();
    }
}
